define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'qikanwenzhang/index' + location.search,
                    add_url: 'qikanwenzhang/add',
                    edit_url: 'qikanwenzhang/edit',
                    del_url: 'qikanwenzhang/del',
                    multi_url: 'qikanwenzhang/multi',
                    import_url: 'qikanwenzhang/import',
                    table: 'qikanwenzhang',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'qikan.name', title: __('Qikan_id'), operate: 'LIKE',},
						{field: 'qikanqishu.year', title: __('Qikanqishu.year'), operate: 'LIKE',},
                        {field: 'qikanqishu.qishu', title: __('Qikanqishu_id'), operate: 'LIKE',},
                        {field: 'qikanwenzhangtype.name', title: __('Qikanwenzhangtype_id')},
                        {field: 'title', title: __('Title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'author', title: __('Author'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'keyword', title: __('Keyword'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'zhongtufenleihao', title: __('Zhongtufenleihao'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'wenxianbiaoshima', title: __('Wenxianbiaoshima'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'wenzhangbianhao', title: __('Wenzhangbianhao'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'content_file', title: __('Content_file'), operate: false, formatter: Table.api.formatter.file},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
				
				$("#c-qikanqishu_id").data("params", function (obj) {
				    //obj为SelectPage对象
				    return {custom: {qikan_id: $("[name='row[qikan_id]']").val()}};
				});
				
				$("#c-qikanwenzhangtype_id").data("params", function (obj) {
				    //obj为SelectPage对象
				    return {custom: {qikan_id: $("[name='row[qikan_id]']").val(),qikanqishu_id:$("[name='row[qikanqishu_id]']").val()}};
				});
				
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
